package group.rober.rax.devkit.service;

import group.rober.rax.devkit.entity.ObjectWindow;
import group.rober.rax.devkit.entity.ObjectWindowCode;
import group.rober.saber.jdbc.DataBeanAccessor;
import group.rober.saber.kit.MapKit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("objectWindowService")
public class ObjectWindowService {
    @Autowired
    protected DataBeanAccessor dataBeanAccessor;

    public List<ObjectWindow> getObjectWindows(){
        String sql = "select * from AWE_DO_CATALOG where 1=1 order by DoType ASC limit 100";
        return dataBeanAccessor.queryList(ObjectWindow.class,sql);
    }

    public List<ObjectWindowCode> getCatalog() {
        String sql = "select * from CODE_LIBRARY where codeno='DOType'";
        return dataBeanAccessor.queryList(ObjectWindowCode.class, sql);
    }

    public List<ObjectWindow> getCatalogList(String doType) {
        Map<String, String> param = MapKit.mapOf(
                "doType", doType
        );
        String sql = "select * from AWE_DO_CATALOG where dotype = :doType";
        return dataBeanAccessor.queryList(ObjectWindow.class, sql, param);
    }

    public List<ObjectWindow> searchObjectWindows(String keyWord){
        Map<String,String> param = MapKit.mapOf(
                "dono","%"+keyWord+"%",
                "doName","%"+keyWord+"%"
        );
        String sql = "select * from AWE_DO_CATALOG where dono like :dono or doName like :doName order by DoType ASC";
        return dataBeanAccessor.queryList(ObjectWindow.class,sql,param);
    }

    public int saveObjectWindow(ObjectWindow objectWindow){
        return dataBeanAccessor.save(objectWindow);
    }

//    public int updateObjectList(ObjectWindow objectWindow) {
//        return dataBeanAccessor.update()
//    }
}
